// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.popman;

import java.util.ArrayList;
import zombie.iso.BuildingDef;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoWorld;
import zombie.iso.RoomDef;

final class PlayerSpawns {
    private final ArrayList<PlayerSpawns.PlayerSpawn> playerSpawns = new ArrayList();

    public void addSpawn(int int0, int int1, int int2) {
        PlayerSpawns.PlayerSpawn playerSpawn = new PlayerSpawns.PlayerSpawn(int0, int1, int2);
        if (playerSpawn.building != null) {
            this.playerSpawns.add(playerSpawn);
        }
    }

    public void update() {
        long _long = System.currentTimeMillis();

        for (int _int = 0; _int < this.playerSpawns.size(); _int++) {
            PlayerSpawns.PlayerSpawn playerSpawn = (PlayerSpawns.PlayerSpawn)this.playerSpawns.get(_int);
            if (playerSpawn.counter == -1L) {
                playerSpawn.counter = _long;
            }

            if (playerSpawn.counter + 10000L <= _long) {
                this.playerSpawns.remove(_int--);
            }
        }
    }

    public boolean allowZombie(IsoGridSquare isoGridSquare) {
        for (int _int = 0; _int < this.playerSpawns.size(); _int++) {
            PlayerSpawns.PlayerSpawn playerSpawn = (PlayerSpawns.PlayerSpawn)this.playerSpawns.get(_int);
            if (!playerSpawn.allowZombie(isoGridSquare)) {
                return false;
            }
        }

        return true;
    }

    private static class PlayerSpawn {
        public int x;
        public int y;
        public long counter;
        public BuildingDef building;

        public PlayerSpawn(int int0, int int1, int int2) {
            this.x = int0;
            this.y = int1;
            this.counter = -1L;
            RoomDef roomDef = IsoWorld.instance.getMetaGrid().getRoomAt(int0, int1, int2);
            if (roomDef != null) {
                this.building = roomDef.getBuilding();
            }
        }

        public boolean allowZombie(IsoGridSquare isoGridSquare) {
            if (this.building == null) {
                return true;
            } else {
                return isoGridSquare.getBuilding() != null && this.building == isoGridSquare.getBuilding().getDef()
                    ? false
                    : isoGridSquare.getX() < this.building.getX() - 15
                        || isoGridSquare.getX() >= this.building.getX2() + 15
                        || isoGridSquare.getY() < this.building.getY() - 15
                        || isoGridSquare.getY() >= this.building.getY2() + 15;
            }
        }
    }
}
